# Open_lots.py
import sys
from PyQt5.QtWidgets import (
    QApplication, QMainWindow, QWidget, 
    QHBoxLayout, QVBoxLayout, QStackedWidget,
    QPushButton, QLabel
)
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt

class StopProfitLossPage(QWidget):
    """止盈止损策略页面"""
    def __init__(self, parent=None):
        super().__init__(parent)
        self.initUI()
        
    def initUI(self):
        layout = QVBoxLayout(self)
        
        # 图片标签
        self.image_label = QLabel(self)
        self.image_label.setAlignment(Qt.AlignCenter)
        self.load_image("img/beauty02.png")  # 确保路径正确
        
        layout.addWidget(self.image_label)
        self.setLayout(layout)
    
    def load_image(self, path):
        pixmap = QPixmap(path)
        if pixmap.isNull():
            self.image_label.setText("图片加载失败")
            return
        # 保持图片比例缩放
        self.image_label.setPixmap(pixmap.scaled(
            self.image_label.size(), 
            Qt.KeepAspectRatio,
            Qt.SmoothTransformation
        ))

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        self.setWindowTitle("交易策略系统")
        self.setGeometry(100, 100, 800, 600)
        
        # 主窗口布局
        main_widget = QWidget()
        self.setCentralWidget(main_widget)
        main_layout = QHBoxLayout(main_widget)
        
        # 左侧控制面板
        left_panel = QWidget()
        left_layout = QVBoxLayout(left_panel)
        
        # 策略启动按钮
        self.start_btn = QPushButton("启动策略止盈止损")
        self.start_btn.clicked.connect(self.show_stop_profit_page)
        left_layout.addWidget(self.start_btn)
        
        # 右侧堆叠窗口
        self.stacked_widget = QStackedWidget()
        
        # 初始化页面
        self.stop_profit_page = StopProfitLossPage()
        self.stacked_widget.addWidget(self.stop_profit_page)
        
        # 添加默认页面（根据需要）
        self.default_page = QLabel("请选择策略")
        self.stacked_widget.addWidget(self.default_page)
        self.stacked_widget.setCurrentIndex(1)
        
        # 布局组装
        main_layout.addWidget(left_panel, stretch=1)
        main_layout.addWidget(self.stacked_widget, stretch=4)
        
    def show_stop_profit_page(self):
        self.stacked_widget.setCurrentIndex(0)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
